package servlet.info;

import pojo.User;
import service.InfoService;
import service.serviceImpl.InfoServiceImpl;
import service.serviceImpl.LogServiceImpl;
import servlet.BaseServlet;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.sql.SQLException;

/**
 * Created by Administrator on 2017-12-10.
 */
public class InfoServlet extends BaseServlet {
    InfoService infoService=new InfoServiceImpl();
    public String info(HttpServletRequest request, HttpServletResponse response){
        return "/jsp/info/info.jsp";
    }
    public String updateInfo(HttpServletRequest request, HttpServletResponse response){
        return "/jsp/info/UpdateInfo.jsp";
    }
    public String UpdateInfo(HttpServletRequest request, HttpServletResponse response) throws SQLException {
        //修改个人信息返回前端
        int result=0;
        HttpSession session=request.getSession();
        User user= (User) session.getAttribute("userInfo");
        int id=user.getId();
        String tl=request.getParameter("tl");
        String password=request.getParameter("old_pwd");
        //查看username是否存在
        User user1= infoService.selectInfo(user.getId());
        if (user1.getPassword().equals(password)){
            String newPassword=request.getParameter("new_pwd");
            //更新信息
            user1.setPassword(newPassword);
            user1.setTl(tl);
            result = infoService.updateInfo(user1);

        }
        request.setAttribute("result",result);
        return "/info?method=info";
    }
}
